import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.handler.codec.string.StringDecoder;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;

public class Server {

    public static void main(String[] args) {

        ServerBootstrap bootStrap = new ServerBootstrap();

        ExecutorService boss = Executors.newCachedThreadPool();
        ExecutorService worker = Executors.newCachedThreadPool();
        bootStrap.setFactory(new NioServerSocketChannelFactory(boss, worker));
        bootStrap.setPipelineFactory(new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline pip = Channels.pipeline();
                pip.addLast("decoder", new StringDecoder());
                pip.addLast("encoder", new StringDecoder());
                pip.addLast("HelloHandle", new MyChannelHandle());
                return pip;
            }
        });
        bootStrap.bind(new InetSocketAddress(8888));
        
        System.out.println("Start");
    }
}
